package domein.models;

import java.util.List;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

import domein.*;

public class DownloadsTableModel extends AbstractTableModel implements Observer 
{	
	private static final long serialVersionUID = 1L;
	private PeerController peerController;
	private String[] columnNames = {"Filename", "Filesize", "Status", "IP-adres Peer"};
    private List<DownloadFile> downloadList = new ArrayList<DownloadFile>();
    
	public DownloadsTableModel(PeerController peerController)
	{
		this.peerController = peerController;
		this.peerController.addObserver(this);
		this.downloadList = PeerController.getInstance().getDownloadFiles();
	}

	@Override
	public int getColumnCount() 
	{
		 return columnNames.length;
	}
	
	@Override
	public int getRowCount() 
	{
        return downloadList.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) 
	{
		return downloadList.get(rowIndex).toArrayList()[columnIndex];
    }
	
	public String getColumnName(int columnIndex)
	{
		return this.columnNames[columnIndex];
	}

	@Override
	public void update() 
	{
		this.downloadList = PeerController.getInstance().getDownloadFiles();
		fireTableDataChanged();
	}
}
